package com.bawei.company

import android.graphics.Color
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.bawei.base.bean.CompanyApplyEntity
import com.bawei.base.mvvm.BaseActivity
import com.bawei.company.databinding.ActivityCompanyApplyBinding
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
@Route(path = "/company/CompanyApplyActivity")
class CompanyapplyActivity : BaseActivity<ActivityCompanyApplyBinding, CompanyViewModel>() {
    var companyApplyAdapter = CompanyapplyAdapter()
    var listCompanyApplyBtYes = mutableListOf<CompanyApplyEntity>()
    var listCompanyApplyBtNo = mutableListOf<CompanyApplyEntity>()

    override fun initView() {
        viewModel.compamyApply()
        binding.companyRec.adapter = companyApplyAdapter
        binding.companyRec.layoutManager = LinearLayoutManager(this)
        binding.companyBeYes.setOnClickListener {
            binding.companyBeYes.setBackgroundColor(Color.GREEN)
            binding.compantyVerify.setBackgroundColor(Color.WHITE)
            companyApplyAdapter.data.clear()
            companyApplyAdapter.data.addAll(listCompanyApplyBtNo)
            companyApplyAdapter.notifyDataSetChanged()
        }
        binding.compantyVerify.setOnClickListener {
            binding.compantyVerify.setBackgroundColor(Color.GREEN)
            binding.companyBeYes.setBackgroundColor(Color.WHITE)

            companyApplyAdapter.data.clear()
            companyApplyAdapter.data.addAll(listCompanyApplyBtYes)
            companyApplyAdapter.notifyDataSetChanged()
        }
        companyApplyAdapter.setOnItemClickListener { adapter, view, position ->
            ARouter.getInstance().build("/company/CompanyApplyDetailActivity")
                .withInt("id", companyApplyAdapter.data[position].id).navigation()
        }
    }

    override fun initData() {
        viewModel.companyApplySuccess.observe(this) {
            it.forEach {
                if (it.status == "新建") {
                    listCompanyApplyBtNo.add(it)
                } else {
                    listCompanyApplyBtYes.add(it)
                }
            }
            companyApplyAdapter.data.clear()
            companyApplyAdapter.data.addAll(listCompanyApplyBtNo)
            companyApplyAdapter.notifyDataSetChanged()
        }
    }
}